package com.example.test.启动线程.读锁与写锁;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class WriteTask implements Runnable{

    private ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true);

    private Lock witeLock = readWriteLock.writeLock();


    @Override
    public void run() {

        witeLock.lock();
        try {
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            witeLock.unlock();
        }

    }
}
